-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject
More file actions
1948 lines (1650 loc) · 47.3 KB
/
project
File metadata and controls
1948 lines (1650 loc) · 47.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// project structure
/src
/main
/java
/com/example/webapp
/controller
- HomeController.java
- UserController.java
- ProductController.java
- OrderController.java
/service
- UserService.java
- ProductService.java
- OrderService.java
/model
- User.java
- Product.java
- Order.java
- Review.java
/repository
- UserRepository.java
- ProductRepository.java
- OrderRepository.java
- WebAppApplication.java
/resources
/static
/css
- style.css
/js
- app.js
/templates
- home.html
- about.html
- contact.html
- userProfile.html
- productList.html
- productDetails.html
- login.html
- orderSummary.html
/application.properties
//web app application
package com.example.webapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@SpringBootApplication
public class WebAppApplication {
public static void main(String[] args) {
SpringApplication.run(WebAppApplication.class, args);
}
}
@EnableWebSecurity
class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/about", "/contact", "/login", "/register").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
}
//user controller
package com.example.webapp.controller;
import com.example.webapp.model.User;
import com.example.webapp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/login")
public String login() {
return "login";
}
@PostMapping("/login")
public String authenticateUser(User user, Model model) {
boolean isValidUser = userService.authenticateUser(user);
if (isValidUser) {
model.addAttribute("user", user);
return "userProfile";
} else {
model.addAttribute("message", "Invalid credentials");
return "login";
}
}
@GetMapping("/register")
public String register() {
return "register";
}
@PostMapping("/register")
public String registerUser(User user, Model model) {
userService.saveUser(user);
model.addAttribute("message", "User registered successfully!");
return "login";
}
}
//product controller
package com.example.webapp.controller;
import com.example.webapp.model.Product;
import com.example.webapp.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@Controller
public class ProductController {
@Autowired
private ProductService productService;
@GetMapping("/products")
public String viewProducts(Model model) {
model.addAttribute("products", productService.getAllProducts());
return "productList";
}
@GetMapping("/product/{id}")
public String viewProductDetails(@PathVariable("id") int id, Model model) {
model.addAttribute("product", productService.getProductById(id));
return "productDetails";
}
}
//order controller
package com.example.webapp.controller;
import com.example.webapp.model.Order;
import com.example.webapp.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class OrderController {
@Autowired
private OrderService orderService;
@GetMapping("/orderSummary")
public String viewOrderSummary(Model model) {
model.addAttribute("orders", orderService.getAllOrders());
return "orderSummary";
}
}
//product service
package com.example.webapp.service;
import com.example.webapp.model.Product;
import org.springframework.stereotype.Service;
@Service
public class ProductService {
public Product[] getAllProducts() {
return new Product[] {
new Product(1, "Car Model A", 1000),
new Product(2, "Car Model B", 1200),
new Product(3, "Car Model C", 1500)
};
}
public Product getProductById(int id) {
// Simulating fetching product by id from a database
return new Product(id, "Car Model " + id, 1000 + (id * 100));
}
}
//order service
package com.example.webapp.service;
import com.example.webapp.model.Order;
import org.springframework.stereotype.Service;
@Service
public class OrderService {
public Order[] getAllOrders() {
return new Order[] {
new Order(1, "Order A", 1000),
new Order(2, "Order B", 1200),
new Order(3, "Order C", 1500)
};
}
}
//user model
package com.example.webapp.model;
public class User {
private String username;
private String password;
private String email;
public User(String username, String password, String email) {
this.username = username;
this.password = password;
this.email = email;
}
// Getters and Setters
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
//product model
package com.example.webapp.model;
public class Product {
private int id;
private String name;
private double price;
public Product(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
// Getters and Setters
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
//order summary
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Summary</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<header>
<h1>Your Orders</h1>
</header>
<main>
<h2>Order Details</h2>
<table>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Price</th>
</tr>
<tr th:each="order : ${orders}">
<td th:text="${order.id}"></td>
<td th:text="${order.name}"></td>
<td th:text="${order.price}"></td>
</tr>
</table>
</main>
<footer>
<p>© 2024 Car Racing WebApp</p>
</footer>
</body>
</html>
//style css
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
header {
background-color: #333;
color: white;
padding: 20px;
text-align: center;
}
main {
padding: 20px;
text-align: center;
}
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
}
table th, table td {
border: 1px solid #ddd;
padding: 10px;
}
footer {
background-color: #333;
color: white;
padding: 10px;
text-align: center;
}
//project 2
import java.util.ArrayList;
import java.util.Scanner;
class Book {
private String title;
private String author;
private String isbn;
public Book(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getIsbn() {
return isbn;
}
public String toString() {
return "Title: " + title + ", Author: " + author + ", ISBN: " + isbn;
}
}
class BookManager {
private ArrayList<Book> books;
public BookManager() {
this.books = new ArrayList<>();
}
public void addBook(String title, String author, String isbn) {
Book newBook = new Book(title, author, isbn);
books.add(newBook);
System.out.println("Book added successfully.");
}
public void viewAllBooks() {
if (books.isEmpty()) {
System.out.println("No books available.");
} else {
System.out.println("Listing all books:");
for (Book book : books) {
System.out.println(book);
}
}
}
public void searchBookByTitle(String title) {
boolean found = false;
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title)) {
System.out.println("Book found: " + book);
found = true;
break;
}
}
if (!found) {
System.out.println("No book found with the title: " + title);
}
}
public void removeBookByTitle(String title) {
boolean removed = false;
for (Book book : books) {
if (book.getTitle().equalsIgnoreCase(title)) {
books.remove(book);
System.out.println("Book removed: " + book);
removed = true;
break;
}
}
if (!removed) {
System.out.println("No book found with the title: " + title);
}
}
}
public class BookManagementSystem {
private static Scanner scanner = new Scanner(System.in);
private static BookManager bookManager = new BookManager();
public static void main(String[] args) {
while (true) {
showMenu();
int choice = getUserChoice();
executeChoice(choice);
}
}
private static void showMenu() {
System.out.println("\nBook Management System");
System.out.println("1. Add a book");
System.out.println("2. View all books");
System.out.println("3. Search book by title");
System.out.println("4. Remove a book");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
}
private static int getUserChoice() {
int choice = -1;
while (choice < 1 || choice > 5) {
try {
choice = Integer.parseInt(scanner.nextLine());
if (choice < 1 || choice > 5) {
System.out.print("Invalid choice. Please choose between 1 and 5: ");
}
} catch (NumberFormatException e) {
System.out.print("Invalid input. Please enter a number between 1 and 5: ");
}
}
return choice;
}
private static void executeChoice(int choice) {
switch (choice) {
case 1:
addBook();
break;
case 2:
bookManager.viewAllBooks();
break;
case 3:
searchBook();
break;
case 4:
removeBook();
break;
case 5:
System.out.println("Exiting system. Goodbye!");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Try again.");
}
}
private static void addBook() {
System.out.print("Enter book title: ");
String title = scanner.nextLine();
System.out.print("Enter author name: ");
String author = scanner.nextLine();
System.out.print("Enter ISBN number: ");
String isbn = scanner.nextLine();
bookManager.addBook(title, author, isbn);
}
private static void searchBook() {
System.out.print("Enter the book title to search: ");
String title = scanner.nextLine();
bookManager.searchBookByTitle(title);
}
private static void removeBook() {
System.out.print("Enter the title of the book to remove: ");
String title = scanner.nextLine();
bookManager.removeBookByTitle(title);
}
}
//project 3
import java.util.ArrayList;
import java.util.Scanner;
class Task {
private String name;
private boolean isCompleted;
public Task(String name) {
this.name = name;
this.isCompleted = false;
}
public String getName() {
return name;
}
public boolean isCompleted() {
return isCompleted;
}
public void markCompleted() {
isCompleted = true;
}
public void markIncomplete() {
isCompleted = false;
}
@Override
public String toString() {
return (isCompleted ? "[Completed] " : "[Pending] ") + name;
}
}
class ToDoList {
private ArrayList<Task> tasks;
public ToDoList() {
tasks = new ArrayList<>();
}
public void addTask(String taskName) {
tasks.add(new Task(taskName));
System.out.println("Task added: " + taskName);
}
public void removeTask(String taskName) {
boolean taskFound = false;
for (Task task : tasks) {
if (task.getName().equalsIgnoreCase(taskName)) {
tasks.remove(task);
System.out.println("Task removed: " + taskName);
taskFound = true;
break;
}
}
if (!taskFound) {
System.out.println("Task not found: " + taskName);
}
}
public void markTaskCompleted(String taskName) {
for (Task task : tasks) {
if (task.getName().equalsIgnoreCase(taskName)) {
task.markCompleted();
System.out.println("Task marked as completed: " + taskName);
return;
}
}
System.out.println("Task not found: " + taskName);
}
public void markTaskIncomplete(String taskName) {
for (Task task : tasks) {
if (task.getName().equalsIgnoreCase(taskName)) {
task.markIncomplete();
System.out.println("Task marked as incomplete: " + taskName);
return;
}
}
System.out.println("Task not found: " + taskName);
}
public void viewAllTasks() {
if (tasks.isEmpty()) {
System.out.println("No tasks available.");
} else {
System.out.println("Your Tasks:");
for (Task task : tasks) {
System.out.println(task);
}
}
}
}
public class ToDoApp {
private static Scanner scanner = new Scanner(System.in);
private static ToDoList toDoList = new ToDoList();
public static void main(String[] args) {
while (true) {
showMenu();
int choice = getUserChoice();
executeChoice(choice);
}
}
private static void showMenu() {
System.out.println("\nTo-Do List Application");
System.out.println("1. Add Task");
System.out.println("2. View All Tasks");
System.out.println("3. Mark Task as Completed");
System.out.println("4. Mark Task as Incomplete");
System.out.println("5. Remove Task");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
}
private static int getUserChoice() {
int choice = -1;
while (choice < 1 || choice > 6) {
try {
choice = Integer.parseInt(scanner.nextLine());
if (choice < 1 || choice > 6) {
System.out.print("Invalid choice. Please choose between 1 and 6: ");
}
} catch (NumberFormatException e) {
System.out.print("Invalid input. Please enter a number between 1 and 6: ");
}
}
return choice;
}
private static void executeChoice(int choice) {
switch (choice) {
case 1:
addTask();
break;
case 2:
toDoList.viewAllTasks();
break;
case 3:
markTaskCompleted();
break;
case 4:
markTaskIncomplete();
break;
case 5:
removeTask();
break;
case 6:
System.out.println("Exiting application. Goodbye!");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Try again.");
}
}
private static void addTask() {
System.out.print("Enter task name: ");
String taskName = scanner.nextLine();
toDoList.addTask(taskName);
}
private static void markTaskCompleted() {
System.out.print("Enter task name to mark as completed: ");
String taskName = scanner.nextLine();
toDoList.markTaskCompleted(taskName);
}
private static void markTaskIncomplete() {
System.out.print("Enter task name to mark as incomplete: ");
String taskName = scanner.nextLine();
toDoList.markTaskIncomplete(taskName);
}
private static void removeTask() {
System.out.print("Enter task name to remove: ");
String taskName = scanner.nextLine();
toDoList.removeTask(taskName);
}
}
// leet code
//two sum
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> numToIndex = new HashMap<>();
for (int i = 0; i < nums.length; ++i) {
if (numToIndex.containsKey(target - nums[i]))
return new int[] {numToIndex.get(target - nums[i]), i};
numToIndex.put(nums[i], i);
}
throw new IllegalArgumentException();
}
}
//add two numbers
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode dummy = new ListNode(0);
ListNode curr = dummy;
int carry = 0;
while (l1 != null || l2 != null || carry > 0) {
if (l1 != null) {
carry += l1.val;
l1 = l1.next;
}
if (l2 != null) {
carry += l2.val;
l2 = l2.next;
}
curr.next = new ListNode(carry % 10);
carry /= 10;
curr = curr.next;
}
return dummy.next;
}
}
//longest sybstring without repeating characters
class Solution {
public int lengthOfLongestSubstring(String s) {
int ans = 0;
int[] count = new int[128];
for (int l = 0, r = 0; r < s.length(); ++r) {
++count[s.charAt(r)];
while (count[s.charAt(r)] > 1)
--count[s.charAt(l++)];
ans = Math.max(ans, r - l + 1);
}
return ans;
}
}
//medain of two sorted arrays
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
final int n1 = nums1.length;
final int n2 = nums2.length;
if (n1 > n2)
return findMedianSortedArrays(nums2, nums1);
int l = 0;
int r = n1;
while (l <= r) {
final int partition1 = (l + r) / 2;
final int partition2 = (n1 + n2 + 1) / 2 - partition1;
final int maxLeft1 = partition1 == 0 ? Integer.MIN_VALUE : nums1[partition1 - 1];
final int maxLeft2 = partition2 == 0 ? Integer.MIN_VALUE : nums2[partition2 - 1];
final int minRight1 = partition1 == n1 ? Integer.MAX_VALUE : nums1[partition1];
final int minRight2 = partition2 == n2 ? Integer.MAX_VALUE : nums2[partition2];
if (maxLeft1 <= minRight2 && maxLeft2 <= minRight1)
return (n1 + n2) % 2 == 0
? (Math.max(maxLeft1, maxLeft2) + Math.min(minRight1, minRight2)) * 0.5
: Math.max(maxLeft1, maxLeft2);
else if (maxLeft1 > minRight2)
r = partition1 - 1;
else
l = partition1 + 1;
}
throw new IllegalArgumentException();
}
}
//longest palindromic substring
class Solution {
public String longestPalindrome(String s) {
if (s.isEmpty())
return "";
// (start, end) indices of the longest palindrome in s
int[] indices = {0, 0};
for (int i = 0; i < s.length(); ++i) {
int[] indices1 = extend(s, i, i);
if (indices1[1] - indices1[0] > indices[1] - indices[0])
indices = indices1;
if (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1)) {
int[] indices2 = extend(s, i, i + 1);
if (indices2[1] - indices2[0] > indices[1] - indices[0])
indices = indices2;
}
}
return s.substring(indices[0], indices[1] + 1);
}
// Returns the (start, end) indices of the longest palindrome extended from
// the substring s[i..j].
private int[] extend(final String s, int i, int j) {
for (; i >= 0 && j < s.length(); --i, ++j)
if (s.charAt(i) != s.charAt(j))
break;
return new int[] {i + 1, j - 1};
}
}
//zigzag conversion
class Solution {
public String convert(String s, int numRows) {
StringBuilder sb = new StringBuilder();
List<Character>[] rows = new List[numRows];
int k = 0;
int direction = numRows == 1 ? 0 : -1;
for (int i = 0; i < numRows; ++i)
rows[i] = new ArrayList<>();
for (final char c : s.toCharArray()) {
rows[k].add(c);
if (k == 0 || k == numRows - 1)
direction *= -1;
k += direction;
}
for (List<Character> row : rows)
for (final char c : row)
sb.append(c);
return sb.toString();
}
}
//reverse integer
class Solution {
public int reverse(int x) {
long ans = 0;
while (x != 0) {
ans = ans * 10 + x % 10;
x /= 10;
}
return (ans < Integer.MIN_VALUE || ans > Integer.MAX_VALUE) ? 0 : (int) ans;
}
}
//string to integer(atoi)
class Solution {
public int myAtoi(String s) {
s = s.strip();
if (s.isEmpty())
return 0;
final int sign = s.charAt(0) == '-' ? -1 : 1;
if (s.charAt(0) == '+' || s.charAt(0) == '-')
s = s.substring(1);
long num = 0;
for (final char c : s.toCharArray()) {
if (!Character.isDigit(c))
break;
num = num * 10 + (c - '0');
if (sign * num <= Integer.MIN_VALUE)
return Integer.MIN_VALUE;
if (sign * num >= Integer.MAX_VALUE)
return Integer.MAX_VALUE;
}
return sign * (int) num;
}
}
//palindrome number
class Solution {
public boolean isPalindrome(int x) {
if (x < 0)
return false;
long reversed = 0;
int y = x;
while (y > 0) {
reversed = reversed * 10 + y % 10;
y /= 10;
}
return reversed == x;
}
}
//regular expression matching
class Solution {
public boolean isMatch(String s, String p) {
final int m = s.length();
final int n = p.length();
// dp[i][j] := true if s[0..i) matches p[0..j)
boolean[][] dp = new boolean[m + 1][n + 1];
dp[0][0] = true;
for (int j = 0; j < p.length(); ++j)
if (p.charAt(j) == '*' && dp[0][j - 1])
dp[0][j + 1] = true;
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
if (p.charAt(j) == '*') {
// The minimum index of '*' is 1.
final boolean noRepeat = dp[i + 1][j - 1];
final boolean doRepeat = isMatch(s, i, p, j - 1) && dp[i][j + 1];
dp[i + 1][j + 1] = noRepeat || doRepeat;
} else if (isMatch(s, i, p, j)) {
dp[i + 1][j + 1] = dp[i][j];
}
return dp[m][n];
}
private boolean isMatch(final String s, int i, final String p, int j) {
return j >= 0 && p.charAt(j) == '.' || s.charAt(i) == p.charAt(j);
}
}
//container with most water
class Solution {
public int maxArea(int[] height) {
int ans = 0;
int l = 0;
int r = height.length - 1;
while (l < r) {
final int minHeight = Math.min(height[l], height[r]);
ans = Math.max(ans, minHeight * (r - l));
if (height[l] < height[r])
++l;
else
--r;
}
return ans;
}
}
//integer to roman
class Solution {
public String intToRoman(int num) {